import Vue from 'vue'
import Router from 'vue-router'
import Layout from '../views/layout'
import Login from '../views/login'
import register from '../views/register/register'
import userList from '../views/components/userList'
Vue.use(Router)
const routes=[
  
  {
  path:'/',
  name:'/',
  children:[{
    path:'userList',
    component:userList
  }],
  component:Layout,
  //路由守卫,如果没有token,就返回登录页面
  beforeEnter:(to,from,next)=>{
    const token=window.sessionStorage.getItem('token');
    if(!token){
      alert("您还没登陆")
      return next('/login')
    }
    next()
  }
},
{
  path:'/login',
  name:'Login',
  component:Login,
},
{
  path:'/register',
  name:'Register',
  component:register,
}
]

export default new Router({
  mode:"history",
  routes
})
